package autokeyboard.data;

import java.util.ArrayList;

/**
 * This class is use to auto press key when you call run() method
 * @author HoldTheHand
 * @version v1.0.0
 */
public class RobotTyping implements Runnable
{
	private boolean isPause = true;
	private boolean isStop = true;
	
	private ArrayList<String[]> listKeyAndDelay;
	
	private RobotData robotData = new RobotData();
	
	private int counter = 0;
	
	public RobotTyping(ArrayList<String[]> listKeyAndDelay)
	{
		this.listKeyAndDelay = listKeyAndDelay;
	}
	
	@Override
	public void run()
	{
		while(!isPause && counter != listKeyAndDelay.size())
		{
			robotData.pressKey(listKeyAndDelay.get(counter)[0], Integer.parseInt(listKeyAndDelay.get(counter)[1]));
			counter++;
		}
		if(counter == listKeyAndDelay.size())
		{
			pause();
			stop();
		}
	}
	
	/**
	 * This method will pause your current auto by change isPause boolean variable into false value
	 */
	public void pause()
	{
		isPause = true;
	}
	
	/**
	 * This method will start/continue your current auto by change isPause boolean variable into true value
	 */
	public void start()
	{
		if(isStop)
		{
			counter = 0;
			isStop = false;
		}
		isPause = false;
	}
	
	public void stop()
	{
		isStop = true;
		isPause = true;
		counter = 0;
	}
	
	
	/**
	 * This method will return your current auto state
	 * <p>
	 * if your current auto is pause or start, this will return false, else it return true
	 * @return isStop variable
	 */
	public boolean getIsStop()
	{
		return this.isStop;
	}

}
